﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestCase_1
{
    class TestQueryBuilderClass
    {
        private string table;
        public string propTable
        {
            get { return table; }
            set { table = value; }
        }

        private string column;
        public string propColumn
        {
            get { return column; }
            set { column = value; }
        }

        private string condition;
        public string propWhere
        {
            get { return condition; }
            set { condition = value; }
        }

        public string TestQueryString()
        {
            string queryString = "Select " + column +  " From " + table + " Where " + condition;  // Query string
            return queryString.Replace("'", "''"); 
        }

        public string executeInsertInto(string TableName, Dictionary<String, Object> Data)
        {
            string columns = "";
            string values = "";
            string rs = "";
            Boolean insertStatus = true;
            foreach (KeyValuePair<String, Object> val in Data)
            {
                columns += String.Format("{0},", val.Key.ToString());
                values += String.Format("{0},", val.Value);

            }
            columns = columns.Substring(0, columns.Length - 1);
            values = values.Substring(0, values.Length - 1);
            try
            {
                 rs = String.Format("Insert into {0}({1}) Values({2});", TableName, columns, values);
            }
            catch (Exception crap)
            {
                insertStatus = false; // Insert fail
                throw new Exception(crap.Message);

            }
            return rs;

        }
    }
}
